package com.drawu.drawuspring.controller;


import com.drawu.drawuspring.domain.DTO.ActivitiesDto;
import com.drawu.drawuspring.domain.Result;
import com.drawu.drawuspring.domain.VO.ActivitiesVo;
import com.drawu.drawuspring.domain.po.Activities;
import com.drawu.drawuspring.service.IActivitiesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hui
 * @since 2025-04-01
 */

@RestController
@RequestMapping("/activities")
@RequiredArgsConstructor
@Tag(name = "活动", description = "活动相关接口")
public class ActivitiesController {

    private final IActivitiesService activitiesService;


    @Operation(summary = "创建活动")
    @PostMapping("/createActivity")
    public Result createActivity(@RequestBody ActivitiesDto dto) {
        return activitiesService.createActivity(dto);
    }

    @Operation(summary = "查询活动")
    @GetMapping("/queryActivity")
    public Result queryActivity(@RequestParam("id") Long id) {
        ActivitiesVo vo = activitiesService.queryActivity(id);
        if (vo == null) {
            return Result.fail("活动不存在");
        }
        return Result.success(vo);
    }

    @Operation(summary = "修改活动")
    @PutMapping("/updateActivity")
    public Result updateActivity(@RequestBody ActivitiesDto dto) {
        return activitiesService.updateActivity(dto);
    }

    @Operation(summary = "删除活动")
    @DeleteMapping("/deleteActivity")
    public Result deleteActivity(@RequestParam("id") Long id) {
        return activitiesService.deleteActivity(id);
    }

    @Operation(summary = "用户加入活动")
    @PostMapping("/joinActivity")
    public Result joinActivity(@RequestParam("activityId") Long activityId, @RequestParam("userId") Integer userId) {
        return activitiesService.joinActivity(activityId, userId);
    }

    @Operation(summary = "用户退出活动")
    @DeleteMapping("/quitActivity")
    public Result quitActivity(@RequestParam("activityId") Long activityId, @RequestParam("userId") Integer userId) {
        return activitiesService.quitActivity(activityId, userId);
    }

    @Operation(summary = "查询所有活动")
    @GetMapping("/queryAllActivities")
    public Result queryAllActivities() {
        return activitiesService.queryAllActivities();
    }

    @Operation(summary = "AI填写活动内容")
    @PostMapping("/aiFill")
    public Result aiFill(@RequestBody ActivitiesDto dto) throws Exception {
        return Result.success(activitiesService.aiFill(dto));
    }
    @Operation(summary = "查询用户参加的活动")
    @GetMapping("/queryUserActivities")
    public Result queryUserActivities() {
        return activitiesService.queryUserActivities();
    }

    @Operation(summary = "查询有某个桌游的活动")
    @GetMapping("/activityWithGame")
    public Result activityWithGame(@RequestParam("gameId") Integer gameId) {
        return activitiesService.activityWithGame(gameId);
    }

    @Operation(summary = "一键生成桌游战报")
    @GetMapping("/generateReport")
    public Result generateReport(@RequestParam("activityId") Integer actId) throws Exception {
        return activitiesService.generateReport(actId);
    }
}
